﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jama;
using Jama.SVD;

namespace JamaTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Matrix matriz;
            double[][] m = new double[4][];
            for (int i = 0; i < 4; i++)
            {
                m[i] = new double[3];
            }
            /*
                    m[0][0] = 1;
                    m[0][1] = 1;
                    m[0][2] = 0;
                    m[1][0] = 0;
                    m[1][1] = 1;
                    m[1][2] = 1;
                    */
            m[0][0] = 1;
            m[0][1] = 2;
            m[0][2] = -1;
            m[1][0] = 3;
            m[1][1] = -4;
            m[1][2] = 1;
            m[2][0] = -1;
            m[2][1] = 3;
            m[2][2] = -1;
            m[3][0] = 2;
            m[3][1] = -1;
            m[3][2] = 0;

            /*
            for(int i = 0; i < 4; i++)
            {
                for(int j =0 ; j < 5; j++)
                {
                    m[i][j] = Math.random();
                }
            }*/

            matriz = new Matrix(m, 4, 3);
            Matrix a = matriz.inverse();
            SingularValueDecomposition svd = matriz.svd();

            Matrix V = svd.getV();
            Matrix S = svd.getS();
            Matrix U = svd.getU();


            Matrix A = U.times(S).times(V.transpose());
            Print(A);
            Console.ReadKey();

        }
        static void Print(Matrix a)
        {
            for (int i = 0; i < a.getRowDimension(); i++)
            {
                for (int j = 0; j < a.getColumnDimension(); j++)
                {
                    Console.Write(a.get(i, j) + " ");
                }
                Console.Write("\n");
            }
        }
    }
}
